#include <string>
#include <memory>
#include <vector>
#include <node_api.h>
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/select.h>

#include "log/serialport_log_wrapper.h"
#include "i_serialport_client.h"
#include "x_napi_tool.h"
#include "serial_async_callback.h"

#define OPTION_SUCCESS        (0)
#define TCGETATTR_ERROR       (-1)
#define DATABITSET_ERROR      (-2)
#define EVENTSET_ERROR        (-3)
#define STOPBITSET_ERROR      (-4)
#define BANDRATE_ERROR        (-5)
#define TCSETATTR_ERROR       (-6)
struct SetOptions_value_struct {
    int32_t in0;
    int32_t in1;
    int32_t in2;
    int32_t in3;
    int32_t in4;
    int32_t out;
};

struct OpenSerial_value_struct {
    std::string in0;
    int32_t out;
};

struct CloseSerial_value_struct {
    int in0;
    int32_t out;
};

struct SendData_value_struct {
    int32_t in0;
    std::vector<uint8_t> in1;
    int32_t out;
};

struct RecvData_value_struct {
    int32_t in0;
    uint32_t len;
    uint32_t timeout;
	std::vector<uint8_t> outData;
	int32_t out;
};

struct setGPIODirection_value_struct {
    int32_t in0;
    bool in1;
    int32_t out;
};

struct setGPIOValue_value_struct {
    int32_t in0;
    int32_t in1;
    int32_t out;
};

struct getGPIOValue_value_struct {
    int32_t in0;
    int32_t out0;
    int32_t out;
};

struct ClearBuffer_value_struct {
    std::string in0;
    uint32_t in1;
    int32_t out;
};

struct Transmit_value_struct {
    std::string in0;
    std::vector<uint8_t> in1;
    uint32_t in2;
    std::vector<uint8_t> outData;
	int32_t out;
};

int32_t SetOptions(int32_t fd, int32_t speeds, int32_t bits, int32_t events, int32_t stops);
int32_t OpenSerial(const char *dev);
int32_t CloseSerial(int32_t fd);
int32_t SendData(int32_t fd, uint8_t *data, int32_t len);
int32_t RecvDat(int32_t fd, uint8_t *data, int32_t len, int32_t timeout);